package com.application.race.manage.action;



import java.util.Map;

import org.apache.mina.core.buffer.IoBuffer;

import com.application.actor.pojo.Actor;
import com.application.race.manage.RacingRoom;
import com.application.race.manage.misc.RacingItem;
import com.application.race.manage.player.Player;
import com.application.race.manage.player.effect.BlastEffect;
import com.application.race.manage.player.effect.CaroticEffect;
import com.application.race.manage.player.effect.CrashEffect;
import com.application.race.manage.player.effect.Effect;
import com.application.race.manage.player.effect.RemoveEffect;
import com.application.race.manage.player.effect.skill.RepairEffect;
import com.application.race.manage.player.effect.skill.StrickEffect;
import com.core.action.ActionConstants;
import com.core.utils.GameUtils;
import com.core.utils.PushDataUtils;
public class Actions {
    public int actionCount=0;
    public Map<Integer,Actor> actors;
    	//names_action=new ArrayList();
    private RacingRoom room;
    public Actions(RacingRoom r){
    	this.room=r;
    }
    public void addItem(RacingItem item){
		IoBuffer sendBuffer = IoBuffer.allocate(128);
		sendBuffer.setAutoExpand(true);
		sendBuffer.putInt(ActionConstants.S2C_ACTION_RACE_ACTION_HEADER);
		sendBuffer.put(ActionConstants.RACE_ACTION_ADDITEM);
 	
		sendBuffer.putInt(item.item.itemId);
		sendBuffer.putInt(item.racingItemid);
    	sendBuffer.putShort((short)item.x);
    	sendBuffer.putShort((short)item.y);
    	
		sendBuffer.flip();
		sendBuffer = GameUtils.Serialize(sendBuffer);
		PushDataUtils.fastPush(sendBuffer, room.actors,
				ActionConstants.RACE_ACTION_ADDITEM);
    }
 
    public void addEffect(Effect eft){
		IoBuffer sendBuffer = IoBuffer.allocate(128);
		sendBuffer.setAutoExpand(true);
		sendBuffer.putInt(ActionConstants.S2C_ACTION_RACE_ACTION_HEADER);
		sendBuffer.put(ActionConstants.RACE_ACTION_EFFECT);
		sendBuffer.put(eft.effectType);
    	
    	switch(eft.effectType){
		 	case Effect.EFFECT_TYPE_UNDER_ATK:
		 	case Effect.EFFECT_TYPE_UNDER_FATAL_ATK_L1:
		 	case Effect.EFFECT_TYPE_UNDER_FATAL_ATK_L2:
		 	case Effect.EFFECT_TYPE_UNDER_FATAL_ATK_L3:
		 		sendBuffer.putInt(eft.receiver);
		 		sendBuffer.putInt(eft.initiator);
		 		sendBuffer.putInt(((CrashEffect) eft).nowBlood);
		 		sendBuffer.putInt(((CrashEffect) eft).absBlood);
		 		break;
		 	case Effect.EFFECT_TYPE_CAROTIC:
		 		sendBuffer.putInt(eft.receiver);
		 		sendBuffer.putInt(eft.initiator);
		 		sendBuffer.putInt(eft.effectId);
		 		sendBuffer.putInt(((CaroticEffect) eft).maxTime);
	    		break;
		 	case Effect.EFFECT_TYPE_REPAIR:
		 		sendBuffer.putInt(eft.receiver);
		 		sendBuffer.putInt(eft.initiator);
		 		sendBuffer.putInt(((RepairEffect) eft).nowBlood);
		 		sendBuffer.putInt(((RepairEffect) eft).addBlood);
	    		break;
		 	case Effect.EFFECT_TYPE_REMOVE:
		 		sendBuffer.putInt(((RemoveEffect) eft).removeType);
		 		sendBuffer.putInt(((RemoveEffect) eft).removeId);
		 		break;
		 	case Effect.EFFECT_TYPE_BLAST:
		 		sendBuffer.putInt(eft.receiver);
		 		sendBuffer.putInt(((BlastEffect) eft).nowBlood);
		 		sendBuffer.putInt(((BlastEffect) eft).absBlood);
		 		break;
		 	case Effect.EFFECT_TYPE_FOCUS:
		 	case Effect.EFFECT_TYPE_DODGE:
		 	case Effect.EFFECT_TYPE_RESIST:
		 	case Effect.EFFECT_TYPE_JUMP:
		 	case Effect.EFFECT_TYPE_HIDE:
		 		sendBuffer.putInt(eft.receiver);
		 		sendBuffer.putInt(eft.initiator);
		 		break;
		 	case Effect.EFFECT_TYPE_STRICK:
		 		sendBuffer.putInt(eft.receiver);
		 		sendBuffer.putInt(eft.initiator);
		 		sendBuffer.putInt(eft.actionid);
		 		sendBuffer.putShort((short)((StrickEffect)eft).x);
		 		sendBuffer.putShort((short)((StrickEffect)eft).y);
		 		sendBuffer.putInt(((StrickEffect)eft).ang);
		 		break;
    	}
		sendBuffer.flip();
		sendBuffer = GameUtils.Serialize(sendBuffer);
		PushDataUtils.fastPush(sendBuffer, room.actors,
				ActionConstants.RACE_ACTION_ADDITEM);
 
 
    }
  
 
 
}
